package com.yshebkb.sulp.dao;

import com.yshebkb.sulp.entity.Menu;
import com.yshebkb.sulp.entity.RoleMenu;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author yshebkb
 */
public interface RoleMenuMapper {
    @Delete({
            "delete from role_menu",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into role_menu (id, role_id, ",
            "menu_id, status, create_time, ",
            "update_time)",
            "values (#{id,jdbcType=BIGINT}, #{roleId,jdbcType=BIGINT}, ",
            "#{menuId,jdbcType=BIGINT}, #{status,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP}, ",
            "#{updateTime,jdbcType=TIMESTAMP})"
    })
    int insert(RoleMenu record);

    int insertSelective(RoleMenu record);

    @Select({
            "select",
            "id, role_id, menu_id, status, create_time, update_time",
            "from role_menu",
            "where id = #{id,jdbcType=BIGINT}"
    })
    RoleMenu selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(RoleMenu record);

    @Update({
            "update role_menu",
            "set role_id = #{roleId,jdbcType=BIGINT},",
            "menu_id = #{menuId,jdbcType=BIGINT},",
            "status = #{status,jdbcType=TINYINT},",
            "create_time = #{createTime,jdbcType=TIMESTAMP},",
            "update_time = #{updateTime,jdbcType=TIMESTAMP}",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(RoleMenu record);

    @Select("select b.* from role_menu a left join menu b on a.menu_id=b.id where a.role_id=#{roleId}")
    List<Menu> findMenusByRoleId(Long roleId);

    List<Menu> findMenusByRoleIds(List<Long> roleIds);
}